package com.chixing.ih.config;

import com.chixing.ih.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-23
 * Time: 21:44
 *
 * @version 1.0
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {
    /**
     * 前台文档访问路径：swagger-ui.html/
     */
    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(this.jwtInterceptor).addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**")
                .excludePathPatterns("favicon.ico").excludePathPatterns("/homePage/pieChaprt")
                .excludePathPatterns("/sys/userLogin").excludePathPatterns("/ih/index")
                .excludePathPatterns("/pay/returnUrl").excludePathPatterns("/pay/notifyUrl")
                .excludePathPatterns("/sys/note/**").excludePathPatterns("/sys/adminLogin")
                .excludePathPatterns("/sys/kaptcha").excludePathPatterns("/sys/image/png")
                .excludePathPatterns("/sys/phone_register").excludePathPatterns("/programmer/programmers")
                .excludePathPatterns("/sys/email_register");
        super.addInterceptors(registry);

    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        registry.addResourceHandler("/")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/csrf")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/favicon.ico")
                .addResourceLocations("classpath:/META-INF/resources/");
        super.addResourceHandlers(registry);
    }


}
